home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DS-CD ROM 2 1993 August
/
DS CD-ROM 2.Ausgabe (August 1993).iso
/
programm
/
ds0257
/
demo.exe
/
MEMORY.DEM
< prev
next >
Wrap
Text File
|
1992-02-16
|
12KB
|
412 lines
; ----------------------------
; MEMORY.DEM - Demoprogramm für die Routinen aus MEMORY.LIB
; (für den A86)
;
; (c) Bernd Schemmer 1992
; Letzter Update: 15.02.1992
;
; Übersetzen:
; A86 MEMORY.DEM DEMOS.INC TO MEMORY.COM
;
; Hinweis: Die Environment-Variable 'A86' muß den Dateinamen 'MACROS.MAC'
; enthalten und die .LIB-Dateien müssen über die Datei A86.LIB
; erreichbar sein.
;
; ---------------------------
jmp start
; ----------------------------
logo db 'MEMORY.DEM - Demo für die Routinen aus MEMORY.LIB',CR,LF
db '-------------------------------------------------',CR,LF
db CR,LF
GETLENGTH Logo
MakeMsg MarkBlock, 'Markiere unseren Speicherblock mittels "SetBlockName" ...'
MakeMsg OwnBlock1, 'Daten des Speicherblocks von MEMORY.COM:'
MakeMsg ShrinkMsg, 'Verkleinere den Speicherblock von MEMORY.COM mittels "SetBlockSize" ...'
MakeMsg OwnBlock2, 'Daten des Speicherblocks von MEMORY.COM nach der Verkleinerung:'
MakeMsg AllocMsg, 'Belege einen Speicherbereich mit 384 K mittels "GetMemoryBlock" ...'
MakeMsg Alloc0Msg, '384 K kriegen wir nicht, nehmen wir, was wir kriegen können ...'
MakeMsg Alloc1Msg, 'Daten des neuen Speicherblocks:'
MakeMsg Alloc2Msg, 'Ermittle die Daten des neuen Blocks über "GetBlockSize" ... '
MakeMsg FreeMsg1, 'Gebe den Block wieder frei mittels "FreeMemoryBlock" ...'
MakeMsg SearchMsg, 'Suche unseren Speicherblock mittels "SearchMemoryBlock" ...'
MakeMsg FoundMsg, 'Unseren Speicherblock gefunden!'
MakeMsg NotFoundMsg,'Nanu, unseren Speicherblock nicht gefunden!'
OurName db 8,'_MEMORY_' ; Name für unseren Speicherblock als String
; ----------------------------
start:
call ShowLogo ; Logo ausgeben und Speicherblock verkleinern
Write_String MarkBlock
; Unseren Speicherblock markieren
mov si,offset OurName
call SetBlockName
call CheckMemoryError
IF c jmp ErrorEnde
Write_String OwnBlock1
call ShowMemoryData
Write_String ShrinkMsg
; akt. Speicherblock verkleinern
mov bx,1000h ; 1 Segment
call SetBlockSize
call CheckMemoryError
if c jmp ErrorEnde
Write_String OwnBlock2
call ShowMemoryData
Write_String AllocMsg
mov bx,06000h
call GetMemoryBlock
jnc >l1 ; okay
; Fehler
cmp ax,08h
jne >l2
push bx
Write_String Alloc0Msg
pop bx
; 1 Segment nicht verfügbar, nehmen wir
; was wir kriegen können
call GetMemoryBlock
jnc >l1
l2:
stc ; Fehler
call CheckMemoryError
IF c jmp ErrorEnde
l1:
mov es,ax
Write_String Alloc1Msg
call ShowMemoryData
call GetBlockSize
call CheckMemoryError
IF c jmp ErrorEnde
call ShowMemoryData1
Write_String FreeMsg1
call FreeMemoryBlock
call CheckMemoryError
IF c jmp ErrorEnde
call ShowMemoryAllocationStrat
IF c jmp ErrorEnde
Write_String SearchMsg
mov si,offset OurName
call SearchMemoryBlock
jc >l1
Write_String FoundMsg
jmp >l2
l1:
Write_String NotFoundMsg
l2:
mov al,0
jmp SHORT Ende
ErrorEnde:
call ShowCR_LF
call OutputMsg
mov al,0FFh
Ende:
EndProcess
ret
; ----------------------------
; ShowMemoryAllocationStrat
;
; Funktion: Ausgabe der akt. Speicherbelegungs-Strategie
;
;
MakeMsg StratMsg1, 'Ermittle die aktuelle Belegungsstrategie mittels "GetMemoryStrategie" ...'
MakeMsg1 StratMsg2, 'Aktuelle Belegungsstrategie ist: '
MakeMsg StratMsg3, 'First Fit'
MakeMsg StratMsg4, 'Best Fit'
MakeMsg StratMsg5, 'Last Fit'
MakeMsg1 StratMsg6, 'UMB only AND '
MakeMsg1 StratMsg7, 'UMB first AND '
ShowMemoryAllocationStrat:
Write_String StratMsg1
Write_String StratMsg2
call GetMemoryStrategy
call CheckMemoryError
IF c ret
push ax
mov ah,030h
int 021h ; DOS-Version berücksichtigen
cmp al,05
pop ax
jb >l2
; ab DOS 5 UMB-Bits berücksichtigen
test al,040h
jz >l1
push ax
Write_String StratMsg6
pop ax
l1:
test al,080h
jz >l2
push ax
Write_String StratMsg7
pop ax
l2:
and al,011xB ; nur die Bits 0 und 1 sind von Bedeutung
or al,al
jne >l1
Write_String StratMsg3
jmp >l2
l1:
dec al
jne >l1
Write_String StratMsg4
jmp >l2
l1:
Write_String StratMsg5
l2:
call ShowCR_LF
clc
ret
; ----------------------------
; ShowMemoryData1
;
; Funktion: Ausgabe der Daten eines Speicherblocks
;
; Eingabe: BX = Größe des Blocks in Paragraphen
; AX = Besitzer des Speicherblocks
;
; Ausgabe: -
;
MemoryBlockMsg1 db
db 'Länge: '
M20 db 'xxxxh Paragraphen, '
db 'Besitzer: '
M40 db 'xxxxh '
db CR,LF
db CR,LF
GETLENGTH MemoryBlockMsg1
ShowMemoryData1:
push es
mov es,cs
push ax
mov ax,bx ; AX = Größe
mov di,offset M20
call Konvert_AX_To_Hexstring
pop ax
; AX = Besitzer
cmp ax,0
jne >l1
; Block ist frei
mov W es:M40,'rf'
mov w es:M40+1,'ie'
mov b es:M40+3,' '
jmp >l2
l1:
cmp ax,08
jne >l1
; Block gehört DOS
mov W es:M40,'OD'
mov w es:M40+1,'S '
mov b es:M40+3,' '
jmp >l2
l1:
; AX = PSP des Besitzers
mov di,offset M40
call Konvert_AX_To_Hexstring
mov al,'h'
stosb
l2:
pop es
Write_String MemoryBlockMsg1
ret
; ----------------------------
; ShowMemoryData
;
; Funktion: Ausgabe der Daten eines Speicherblocks
;
; Eingabe: ES = Segment des Speicherblocks
;
; Ausgabe: -
;
MemoryBlockMsg db 'Adresse: '
M1 db 'xxxxh, Länge: '
M2 db 'xxxxh Paragraphen, '
db 'Besitzer: '
M4 db 'xxxxh, Name: '
M5 db 'xxxxxxxx'
db CR,LF
db CR,LF
GETLENGTH MemoryBlockMsg
ShowMemoryData:
push ds,es
mov ax,es
dec ax
mov ds,ax ; DS = MCB des Speicherblocks
mov ax,es ; AX = Segment
push cs
pop es ; ES = CS
mov di,offset M1
call Konvert_AX_To_HexString
mov ax,[03] ; AX = Länge in Paragraphen
mov di,offset M2
call Konvert_AX_TO_Hexstring
mov ax,[01] ; AX = Besitzer
cmp ax,0
jne >l1
; Block ist frei
mov W es:M4,'rf'
mov w es:M4+1,'ie'
mov b es:M4+3,' '
jmp >l2
l1:
cmp ax,08
jne >l1
; Block gehört DOS
mov W es:M4,'OD'
mov w es:M4+1,'S '
mov b es:M4+3,' '
jmp >l2
l1:
; AX = PSP des Besitzers
mov di,offset M4
call Konvert_AX_To_Hexstring
mov al,'h'
stosb
l2:
; Name erstmal löschen
mov di,offset M5
mov ax,'--'
stosw
stosw
stosw
stosw
pop es ; ES = Segment
push es
mov ds,cs
mov si,offset M5-1
mov al,[si]
push ax
call GetOwnerName
pop ax
mov [si],al
pop es,ds
Write_String MemoryBlockMsg
ret
; ----------------------------
; CheckMemoryError
;
; Funktion: Ermitteln der zu einer Fehlernummer
; gehörenden Fehlermeldung
;
; Eingabe: AX = Fehlercode der Routine
; CF = CF der Routine
;
; Ausgabe: CF = 0 ->> kein Fehler
; kein Register verändert
; CF = 1 ->> Fehler
; DX = Offset der Fehlermeldung
; CX = Länge der Fehlermeldung
; AX unverändert
;
; Fehlermeldungen
; ---------------
MErrMsg0 db '*** Fehler in der MCB-Kette'
MErrMsg1 db '*** Zuwenig freier Speicher'
MErrMSg2 db '*** Falsche Speicherblockadresse angegeben (DOS-Fehler 9)'
MErrMsg3 db '*** Falsche Blockadresse angegeben'
MErrMsg4 db '*** Falsche Blockgröße angegeben'
MErrMsg5 db '*** Der Block ist frei'
MErrMsg6 db '*** Der Block gehört DOS'
MErrMsg7 db '*** Der Block ist kein Hauptblock'
MErrMsg8 db '*** Falscher Name für den Block angegeben'
MErrMsg9 db '*** Block nicht gefunden'
MErrMsgU db '*** Unbekannter Fehlercode'
MErrmsgL db ' '
; Tabelle der Fehlernummern und Fehlermeldungen
; ---------------------------------------------
; Fehlernummern Offset der Fehlermeldung
; -----------------------------------------------
MErrMsgTable dw 07 , Offset MErrMsg0
dw 08 , Offset MErrMsg1
dw 09 , Offset MErrMsg2
dw MemoryBlockError , Offset MErrMsg3
dw InvalidBlockLength , Offset MErrMsg4
dw BlockIsFree , Offset MErrMsg5
dw BlockBelongsToDOS , Offset MErrMsg6
dw BlockIsNoMainBlock , Offset MErrMsg7
dw InvalidBlockName , Offset MErrMsg8
dw BlockNotFound , Offset MErrMsg9
; Eintrag für unbekannte Fehlercodes
MErrUnknown dw 0 , Offset MErrMsgU
; Eintrag für die Ermittlung der Länge
; der letzten Fehlermeldung
dw 0 , Offset MErrMsgL
CheckMemoryError:
jnc ret ; CF = 0 ->> kein Fehler aufgetreten
push si,ds,ax ; CF = 1 ->> Fehler aufgetreten,
; Offset der Fehlermeldung ermitteln
mov ds,cs ; DS = CS
mov si,offset MErrMsgTable
; DS:SI -> Fehlertabelle
; Eintrag für unbekannte Fehlercodes korrigieren
mov MErrUnknown,ax
mov dx,ax ; Fehlernummer nach DX
l0:
lodsw
cmp ax,dx
lodsw
jne l0
mov dx,ax ; DX = Offset der Fehlermeldung
mov cx,[si+2] ; CX = Offset der nächsten Fehlermeldung
sub cx,dx ; CX = Länge der Fehlermeldung
stc
pop ax,ds,si
ret